package com.xxgc.eow.service.impl;

import com.xxgc.eow.entity.Article;
import com.xxgc.eow.entity.Likearticle;
import com.xxgc.eow.mapper.LikearticleMapper;
import com.xxgc.eow.service.ILikearticleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * <p>
 * 点赞文章表 服务实现类
 * </p>
 *
 * @author Mr.Abel
 * @since 2023-05-25
 */
@Service
public class LikearticleServiceImpl extends ServiceImpl<LikearticleMapper, Likearticle> implements ILikearticleService {

    @Resource
    private LikearticleMapper likearticleMapper;

    @Override
    public int insertLikeArticle(Likearticle likearticle) {
        Date date = new Date();
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
        likearticle.setCreateTime(localDateTime);
        return likearticleMapper.insertLikeArticle(likearticle);
    }

    @Override
    public Integer getArticleById(int articleId) {
        return likearticleMapper.getArticleById(articleId);
    }

    @Override
    public int updateLike(int articleId, int likeNum) {
        return likearticleMapper.updateArticleLike(articleId,likeNum);
    }

    @Override
    public int delLikeArticle(Likearticle likearticle) {
        Date date = new Date();
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
        likearticle.setDestroyTime(localDateTime);
        return likearticleMapper.delLikeArticle(likearticle);
    }

    @Override
    public Likearticle selectTfData(Likearticle likearticle) {
        return likearticleMapper.selectTfData(likearticle);
    }
}
